package com.sky.robot.frame.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sky.robot.commons.utils.Result;
import com.sky.robot.frame.entity.SkyTableColumn;
import com.sky.robot.frame.service.SkyTableColumnService;
import com.sky.robot.frame.utils.SkyPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/core/skyTableColumn" )
public class SkyTableColumnController {

    @Autowired
    private SkyTableColumnService skyTableColumnService;

    /**
     * 前端页面传过来第几页，每一页数据数量
     */
    @PostMapping("/listPage" )
    public Object listPage(@RequestBody Map<String, Object> params) {
        Integer pageNum = Integer.parseInt((String) params.get("pageNum" )); // 获取第几页
        Integer pageSize = Integer.parseInt((String) params.get("pageSize" )); // 每页多少条数据
        IPage<SkyTableColumn> page = new SkyPage<>(pageNum, pageSize);
        Object obj = skyTableColumnService.listPage(page, params);
        return Result.success(obj);
    }

    @PostMapping("/get" )
    public Object get(@RequestBody Map<String, Object> params) {
        Object obj = skyTableColumnService.get(params);
        return obj;
    }

    /**
     * 保存
     */
    @PostMapping("/add" )
    public Result<?> add(@RequestBody SkyTableColumn skyTableColumn) {
        Object obj = skyTableColumnService.add(skyTableColumn);
        return Result.success(obj);
    }

    /**
     * 修改
     */
    @PutMapping("/edit" )
    public Result<?> edit(@RequestBody SkyTableColumn skyTableColumn) {
        Object obj = skyTableColumnService.edit(skyTableColumn);
        return Result.success(obj);
    }

    /**
     * 通过id删除
     */

    @DeleteMapping("/delete" )
    public Result<?> delete(String id) {
        skyTableColumnService.delete(id);
        return Result.success(id);
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/deleteBatch" )
    public Result<?> deleteBatch(@RequestParam("ids" ) String ids) {
        skyTableColumnService.deleteBatch(ids);
        return Result.success(ids);
    }

}
